<?php
require_once '../include/common.inc.php';
//require_once '../login/login_check.php';
require_once 'ad.php';
$tablename;
if ($type == "0")
{
	$tablename = "userinfo";
}
else if($type == "1")
{
	$tablename = "softinfo";
}
else if($type == "2")
{
	$tablename = "package";
}
else if($type == "3")
{
	$tablename = "SalesOrder";
}
else if($type == "4")
{
	$tablename = "Operationlog";
}
	
$query = "select count(*) as counte from $tablename";
$result = $db->query ( $query );
$list = $db->fetch_array ( $result );
$total = $list [counte];
if (! $page)
	$page = 1;
$firstcount = 20 * ($page - 1);
$displaypg = 20;
$pageCount = $total / $displaypg;
if ($total % $displaypg)
	$pageCount += 1;
	
	
$queryTestUserCount = "select count(*) as counte from (select username from Operationlog group by username) as table1";
$result = $db->query ( $queryTestUserCount );
$list = $db->fetch_array ( $result );
$TestUserCount = $list [counte];

$queryTestImeiCount = "select count(*) as counte from (select imei from Operationlog group by imei) as table1";
$result = $db->query ( $queryTestImeiCount );
$list = $db->fetch_array ( $result );
$TestImeiCount = $list [counte];
	
$query = "select * from $tablename order by id DESC limit $firstcount,$displaypg";
if ($type == "3")
{
	$query = "select US.id as userid, SO.id as softid, PA.id as packageid ,US.name as username,SO.name as softname, PA.name as packagename,SA.ordertime,SA.isovertime
			  from SalesOrder SA,userinfo US,softinfo SO,package PA where SA.userid = US.id and SA.softid = SO.id
			  and SA.packageid = PA.id order by SA.id DESC limit $firstcount,$displaypg";
}

$result = $db->query ( $query );
?>
<?php if($type == "0"){?>
		<table width="62%" border="1" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000" cellspading="1" >
		<tr><td width="20%">用户名称</td>
		<td width="32%">联系电话</td>
		<td width="33%">邮箱</td>
		<td width="15%">操作</td>
		</tr>
		<?php
		while ( $list = $db->fetch_array ( $result ) ) {
		?>
			<tr><td width="20%"><a href="adduser.php?action=0&id=<?php echo $list[id]?>">
			<?php
				echo "$list[name]";
			?>
			</a></td>
			<td width="32%">
			<?php
				echo "$list[tel]";
			?>	</td>
			<td width="33%">
			<?php
				echo "$list[email]";
			?>	</td>
			<td>
			  <p>
			  <a href="delete?type=0&id=<?php echo $list[id]?>">删除</a></td>
			</tr>
		<?php }?>
			<tr>
			  <td colspan="3">
			  	<?php if ($page > 1) {?><a href="list.php?type=0&page=<?php echo ($page - 1)?>">上一页</a><?php }?>
			  	<?php if ($page < $pageCount - 1) {?><a href="list.php?type=0&page=<?php echo ($page + 1)?>">下一页</a><?php }?>
			  </td>
			  <td><a href="adduser.php?action=1">添加</a></td>
			</tr>
		</table>
<?php } else if($type == "1"){?>
		<table width="62%" border="1" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000" cellspading="1" >
		<tr><td width="20%">软件名称</td>
		<td width="32%">软件版本号</td>
		<td width="33%">文件版本号</td>
		<td width="15%">操作</td>
		</tr>
		<?php
		while ( $list = $db->fetch_array ( $result ) ) {
		?>
			<tr><td width="20%"><a href="addsoft.php?action=0&id=<?php echo $list[id]?>">
			<?php
				echo "$list[name]";
			?>
			</a></td>
			<td width="32%">
			<?php
				echo "$list[softver]";
			?>	</td>
			<td width="33%">
			<?php
				echo "$list[filever]";
			?>	</td>
			<td>
			  <p>
			  <a href="delete?type=1&id=<?php echo $list[id]?>">删除</a></td>
			</tr>
		<?php }?>
			<tr>
			  <td colspan="3">
			  	<?php if ($page > 1) {?><a href="list.php?type=1&page=<?php echo ($page - 1)?>">上一页</a><?php }?>
			  	<?php if ($page < $pageCount - 1) {?><a href="list.php?type=1&page=<?php echo ($page + 1)?>">下一页</a><?php }?>
			  </td>
			  <td><a href="addsoft.php?action=1">添加</a></td>
			</tr>
		</table>
<?php } else if($type == "2"){?>
		<table width="62%" border="1" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000" cellspading="1" >
		<tr><td width="20%">套餐名称</td>
		<td width="32%">套餐价格(元)</td>
		<td width="33%">服务时间(月)</td>
		<td width="15%">操作</td>
		</tr>
		<?php
		while ( $list = $db->fetch_array ( $result ) ) {
		?>
			<tr><td width="20%"><a href="addpackage.php?action=0&id=<?php echo $list[id]?>">
			<?php
				echo "$list[name]";
			?>
			</a></td>
			<td width="32%">
			<?php
				echo "$list[money]";
			?>	</td>
			<td width="33%">
			<?php
				echo "$list[service]";
			?>	</td>
			<td>
			  <p>
			  <a href="delete?type=2&id=<?php echo $list[id]?>">删除</a></td>
			</tr>
		<?php }?>
			<tr>
			  <td colspan="3">
			  	<?php if ($page > 1) {?><a href="list.php?type=2&page=<?php echo ($page - 1)?>">上一页</a><?php }?>
			  	<?php if ($page < $pageCount - 1) {?><a href="list.php?type=2&page=<?php echo ($page + 1)?>">下一页</a><?php }?>
			  </td>
			  <td><a href="addpackage.php?action=1">添加</a></td>
			</tr>
		</table>
<?php } else if($type == "3"){?>
		<table width="62%" border="1" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000" cellspading="1" >
		<tr><td width="20%">用户名称</td>
		<td width="25%">软件名称</td>
		<td width="25%">套餐名称</td>
		<td width="15%">下订时间</td>
		<td width="15%">过期标志</td>
		</tr>
		<?php
		while ( $list = $db->fetch_array ( $result ) ) {
		?>
			<tr><td width="20%"><a href="adduser.php?action=0&id=<?php echo $list[userid]?>">
			<?php
				echo "$list[username]";
			?>
			</a></td>
			<td width="25%"><a href="addsoft.php?action=0&id=<?php echo $list[softid]?>">
			<?php
				echo "$list[softname]";
			?>	</a></td>
			<td width="25%"><a href="addpackage.php?action=0&id=<?php echo $list[packageid]?>">
			<?php
				echo "$list[packagename]";
			?>	</td>
			<td width="15%">
			<?php
				echo "$list[ordertime]";
			?>	</td>
			<td width="15%">
			<?php
				echo "$list[isovertime]";
			?>	</td>
			</tr>
		<?php }?>
			<tr>
			  <td colspan="3">
			  	<?php if ($page > 1) {?><a href="list.php?type=3&page=<?php echo ($page - 1)?>">上一页</a><?php }?>
			  	<?php if ($page < $pageCount - 1) {?><a href="list.php?type=3&page=<?php echo ($page + 1)?>">下一页</a><?php }?>
			  </td>
			</tr>
		</table>
<?php } else if($type == "4"){?>
		<table width="62%" border="1" align="center" cellpadding="2" cellspacing="1" bordercolor="#000000" cellspading="1" >
		<tr><td width="20%">用户名称</td>
		<td width="25%">软件名称</td>
		<td width="25%">IMEI</td>
		<td width="15%">操作时间</td>
		</tr>
		<?php
		while ( $list = $db->fetch_array ( $result ) ) {
		?>
			<tr><td width="20%">
			<?php
				echo "$list[username]";
			?>
			</td>
			<td width="25%">
			<?php
				echo "$list[softcode]";
			?></td>
			<td width="25%">
			<?php
				echo "$list[imei]";
			?>	</td>
			<td width="15%">
			<?php
				echo "$list[Operationtime]";
			?>	</td>
			</tr>
		<?php }?>
			<tr>
			  <td colspan="3">
			  	<?php if ($page > 1) {?><a href="list.php?type=4&page=<?php echo ($page - 1)?>">上一页</a><?php }?>
			  	<?php if ($page < $pageCount - 1) {?><a href="list.php?type=4&page=<?php echo ($page + 1)?>">下一页</a><?php }?>
			  </td>
			  <td colspan="3" width="50%">
			  	<table width="100%">
				  	<tr width="100%"><?php echo "总试用人数:".$TestUserCount; ?></tr>
				  	<tr width="100%"><?php echo "总试用手机数".$TestImeiCount; ?></tr>
			  	</table>
			  </td>
			</tr>
		</table>
<?php }?>



<?php
require_once '../ad.php';
?>